import { createRouter, createWebHashHistory } from 'vue-router'
const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      name: 'index',
      path: '/',
      component: () => import('../pages/index/index.vue')
    },
    {
      name: 'other',
      path: '/other',
      component: () => import('../pages/index/other.vue')
    },
    {
      name: 'daydayup',
      path: '/daydayup',
      component: () => import('../pages/daydayup/index.vue'),
      children: [
        {
          name: 'test',
          path: 'test',
          component: () => import('../pages/daydayup/241015_child.vue')
        }
      ]
    },
    {
      name: 'list',
      path: '/list',
      component: () => import('../pages/daydayup/241016/list.vue'),
      meta: {
        keepAlive: true
      }
    },
    {
      name: 'detail',
      path: '/detail',
      component: () => import('../pages/daydayup/241016/detail.vue')
    },
    {
      name: 'test',
      path: '/test',
      component: () => import('../json/test/index.vue')
    },
    {
      name: 'leave',
      path: '/leave',
      component: () => import('../pages/index/leave.vue')
    },
    {
      name: 'category',
      path: '/category/:id?',
      meta: {
        comefrom: 0
      },
      redirect: {
        name: 'category.index'
      },
      alias: '/categoryAias',
      component: () => import('../pages/daydayup/category/index.vue'),
      children: [
        {
          name: 'category.index',
          path: 'index',
          meta: {
            other: 1
          }
        },
        {
          name: 'category.l1',
          path: 'l1',
          meta: {
            other: 2
          },
          component: () => import('../pages/daydayup/category/l1.vue')
        },
        {
          name: 'category.l2',
          path: 'l2',
          meta: {
            other: 3
          },
          component: () => import('../pages/daydayup/category/l2.vue')
        }
      ]
    },
    {
      name: 'geolocation',
      path: '/geolocation',
      component: () => import('../pages/daydayup/geolocation.vue')
    }
  ]
})

router.beforeEach((to, from, next) => {
  console.log(to, from)
  //console.log(from.matched[0].instances.default.a);
  to.meta.from = from.matched[0]?.instances.default
  next()
})

router.afterEach((to, from) => {
  console.log(`afterEach`, to, from)
})

export default router
